<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>arrow code view</title>
    <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.css"> -->
    <link rel="stylesheet" href="../highlight/styles/github-dark.css">
    <script src="../highlight/highlight.min.js"></script>
    <script>hljs.highlightAll();</script>
    <style>
        body {
            margin: 0;
            display: flex;
            height: 100vh;
            font-family: Arial, sans-serif;
        }

        .sidebar {
            width: 250px;
            background-color: #2c3e50;
            color: white;
            display: flex;
            flex-direction: column;
            padding: 10px;
        }

        .sidebar h2 {
            word-wrap: break-word;
            /* 或者使用 word-break: break-all; 根据需要选择 */
        }
        .file-path {
            position: fixed; /* 固定在窗口 */
            height: 20px;
            width: 100%;
            overflow-x: auto;
            background-color: #34495e;
            color: white;
            padding: 10px;
            text-align: center;
        }

        .file-tree {
            flex: 1;
            overflow-y: auto;
            margin-top: 20px;
        }

        .file {
            padding: 5px;
            cursor: pointer;
            border-radius: 3px;
        }

        .file:hover {
            background-color: #34495e;
        }

        .editor-container {
            flex: 1;
            display: flex;
            flex-direction: column;
        }

        .navbar {
            background-color: #34495e;
            color: white;
            padding: 10px;
            text-align: center;
        }

        .code {
            flex: 1;
            overflow-y: auto;
        }

        .codemirror-container {
            flex: 1;
            padding: 10px;
        }

        .controls {
            height: 50px;
            background-color: #ecf0f1;
            border-top: 1px solid #bdc3c7;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }

        .control-button {
            background-color: #2c3e50;
            color: white;
            padding: 10px 20px;
            border: none;
            cursor: pointer;
            border-radius: 5px;
        }

        .control-button:hover {
            background-color: #34495e;
        }
    </style>
</head>
<body>
    <!-- <div class="file-path">file all path</div> -->
    <div class="sidebar">
        <h2>file folder path</h2>
        <div class="file-tree">
            <div class="file" onclick="onFileClick('index.html')">index.html</div>
            <div class="file" onclick="onFileClick('styles.css')">styles.css</div>
            <div class="file" onclick="onFileClick('script.js')">script.js</div>
        </div>
    </div>
    <div class="editor-container">
        <div class="navbar">file all path</div>
        <div class="code">
            <pre><code class="cpp">
                // 在这里粘贴你的C++代码
                #include "session_manager.h"
                #include "nlohmann/json.hpp"
                #include "../common/common.h"
                
                namespace ArrowWebSocket
                {
                
                CSessionManager::CSessionManager()
                {
                }
                
                CSessionManager::~CSessionManager()
                {
                    Deini();
                }
                
                void CSessionManager::Init(asio::io_context& ioContext)
                {
                    m_pTimer = new asio::steady_timer(ioContext);
                }
                
                void CSessionManager::Run()
                {
                    DoReadQueue();
                    return;
                }
                
                void CSessionManager::Deini()
                {
                    if(m_pTimer != nullptr)
                    {
                        m_pTimer->cancel();
                        delete m_pTimer;
                        m_pTimer = nullptr;
                    }
                }
                
                void CSessionManager::AddSession(SharedPtrISession pSession)
                {
                    if(m_setSessions.find(pSession) != m_setSessions.end())
                        return;
                
                    if(m_setMsgSrcInfo.size() > 0 )
                    {
                        std::string strTmpAllMsgSrcInfo;
                        nlohmann::json j;
                        for (auto& it : m_setMsgSrcInfo)
                        {
                            j.push_back(it);
                        }
                        strTmpAllMsgSrcInfo = j.dump();
                        pSession->PutAllMsgSrcInfo(strTmpAllMsgSrcInfo);
                    }
                
                    m_setSessions.insert(pSession);
                }
                
                void CSessionManager::RemoveSession(SharedPtrISession pSession)
                {
                    m_setSessions.erase(pSession);
                    if(m_setSessions.size() == 0)
                    {
                        m_setMsgSrcInfo.clear();
                    }
                }
                
                void CSessionManager::PutMsg(const SharedPtrMsg& pMsg)
                {
                    m_msgQueue.Push(pMsg);
                }
                
                void CSessionManager::DoReadQueue()
                {
                    // if (m_msgQueue.Empty())
                    // {
                    //     // 启动定时器 10毫秒后再次调用
                    //     m_pTimer->expires_after(std::chrono::milliseconds(10));
                    //     m_pTimer->async_wait([this](beast::error_code ec) {
                    //         if (!ec)
                    //         {
                    //             DoReadQueue();
                    //         }
                    //     });
                    //     return;
                    // }
                    // SharedPtrMsg pMsg;
                    // if( false == m_msgQueue.Pop(pMsg))
                    // {
                    //     return;
                    // }
                
                    // auto it = m_setMsgSrcInfo.find(pMsg->SrcInfo());
                    // if(it == m_setMsgSrcInfo.end())
                    // {
                    //     m_setMsgSrcInfo.insert(pMsg->SrcInfo());
                    //     nlohmann::json j;
                    //     j["msg_type"] = static_cast<int32_t>(EmMsgType::AllMsgSrcInfo);
                    //     for (auto& it : m_setMsgSrcInfo)
                    //     {
                    //         j["msg_src_info"].push_back(it);
                    //     }
                    //     std::string strtmp = j.dump();
                
                    //     for (auto& it : m_setSessions)
                    //     {
                    //         it->PutAllMsgSrcInfo(strtmp);
                    //     }
                    // }
                
                    // for (auto& it : m_setSessions)
                    // {
                    //     it->PutMsg(pMsg);
                    // }    
                    // DoReadQueue();
                }
                
                int32_t CSessionManager::Count()
                {
                    return m_setSessions.size();
                }
                
                } // namespace ArrowWebSocket
                
                </code></pre>
        </div>
    </div>

    <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/javascript/javascript.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/css/css.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/xml/xml.min.js"></script>
    <script>
        var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
            lineNumbers: true,
            mode: "javascript",
            theme: "default"
        });
    </script> -->
</body>
</html>
